<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>upload</title>
    <script type="text/javascript" src="../lib/js/jquery3.6.0.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#upload").click(function () {
                var formData = new FormData($('#uploadForm')[0]);
                $.ajax({
                    type: 'post',
                    url: "http://localhost:8080/d0915/test/upload", //上传文件的请求路径必须是绝对路劲
                    data: formData,
                    cache: false,
                    processData: false,
                    contentType: false,
                }).success(function (data) {
                    alert(data);
                }).error(function () {
                    alert("上传失败");
                });
            });
        });
    </script>
</head>
<!--<body>
上传
<input type="file" src="./bookstoreImg">
<button id="sub">提交</button>
</body>-->
<body>
<form id="uploadForm" method="post" enctype="multipart/form-data">
    文件:<input id="file" type="file" name="file"/>
    <button id="upload">上传文件</button>
</form>
</body>


</html>